﻿Imports System.Random
Public Class frmMain
    Private _lastResultLeft1 As Integer
    Private _lastresultRight1 As Integer
    Private _lastResultLeft2 As Integer
    Private _lastresultRight2 As Integer
    Private _rand As New Random

#Region "Events"
    ''' <summary>
    ''' Exits the program
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mnuExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    ''' <summary>
    ''' Clears the history richtext
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ClearHistoryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearHistoryToolStripMenuItem.Click
        rtxtHistory.Clear()
    End Sub

    ''' <summary>
    ''' Calls up the about form
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mnuAboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAboutToolStripMenuItem.Click
        Dim abt As New frmAbout
        abt.ShowDialog()
    End Sub

    ''' <summary>
    ''' Allows only numbers and controls like enter, tab, etc.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtNumberOnly_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTarget1.KeyPress, txtMOS.KeyPress, txtDamageDice.KeyPress, txtArmor.KeyPress, txtTarget2.KeyPress
        If Char.IsNumber(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
            e.Handled = True
        End If
    End Sub

    ''' <summary>
    ''' Allows only numbers, dash (for negative), and controls like enter, tab, etc.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtNegative_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAP.KeyPress, txtDamageBonus.KeyPress
        If e.KeyChar <> Char.Parse("-") And Char.IsNumber(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
            e.Handled = True
        End If
    End Sub

    ''' <summary>
    ''' Allows only numbers, dot, and controls like enter, tab, etc.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtDecimal_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTimeframe.KeyPress
        If e.KeyChar <> Char.Parse(".") And Char.IsNumber(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
            e.Handled = True
        End If
    End Sub

    ''' <summary>
    ''' Goes to the roll button when hitting enter
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtTarget1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTarget1.KeyDown, txtTarget2.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnRoll.Focus()
        End If
    End Sub

    ''' <summary>
    ''' Keeps the various form elements hidden or shown when needed
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoNormal.CheckedChanged, rdoTask.CheckedChanged, rdoSimple.CheckedChanged, rdoOpposed.CheckedChanged, rdoMargin.CheckedChanged, rdoDamage.CheckedChanged
        grpMOS.Visible = rdoMargin.Checked
        pnlOpposed.Visible = rdoOpposed.Checked
        btnMox2.Visible = rdoOpposed.Checked
        btnMoxBoth.Visible = rdoOpposed.Checked
        grpTaskTimeframe.Visible = rdoTask.Checked
        grpDamage.Visible = rdoDamage.Checked
        grpTarget1.Visible = Not rdoDamage.Checked
        grpMoxieInvert.Visible = Not rdoDamage.Checked
    End Sub

    ''' <summary>
    ''' Calls for a random roll
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnRoll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoll.Click
        DoRolls()
    End Sub

    ''' <summary>
    ''' Inverts the left and right values of char 1's last results and sends it back in to be reshown
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnMox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMox1.Click
        DoRolls(_lastresultRight1, _lastResultLeft1, _lastResultLeft2, _lastresultRight2)
    End Sub

    ''' <summary>
    ''' Inverts the left and right values of char 2's last results and sends it back in to be reshown
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnMox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMox2.Click
        DoRolls(_lastResultLeft1, _lastresultRight1, _lastresultRight2, _lastResultLeft2)
    End Sub

    ''' <summary>
    ''' Inverts the left and right values of char 1 and 2's last results and sends it back in to be reshown
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnMoxBoth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoxBoth.Click
        DoRolls(_lastresultRight1, _lastResultLeft1, _lastresultRight2, _lastResultLeft2)
    End Sub
#End Region
  
#Region "Roll and Report Functions"
    ''' <summary>
    ''' Workhorse of the program
    ''' </summary>
    ''' <param name="ResLeft1">Moxie invert result left 1, -1 for not used</param>
    ''' <param name="ResRight1">Moxie invert result right 1, -1 for not used</param>
    ''' <param name="ResLeft2">Moxie invert result left 2, -1 for not used</param>
    ''' <param name="ResRight2">Moxie invert result right 2, -1 for not used</param>
    ''' <remarks></remarks>
    Private Sub DoRolls(Optional ByVal ResLeft1 As Integer = -1, Optional ByVal ResRight1 As Integer = -1, Optional ByVal ResLeft2 As Integer = -1, Optional ByVal ResRight2 As Integer = -1)

        If Not rdoDamage.Checked Then
            Dim baseTN1, result1, MOS1, MOF1 As Integer
            Dim baseSucc1, critical1, excellent1, severe1
            DoBaseRoll(txtTarget1, ResLeft1, ResRight1, _lastResultLeft1, _lastresultRight1, baseTN1, result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1)

            If rdoNormal.Checked Then
                'report basic success/fail with crits and MOS/MOF
                ReportNormal(result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1)
            ElseIf rdoSimple.Checked Then
                'report strong or weak success and crits and MOS/MOF
                ReportSimple(result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1)
            ElseIf rdoMargin.Checked Then
                If txtMOS.Text = "" Then
                    MsgBox("You need to enter a Margin of Succes value of at least 0 in the MOS Minimum box in order to roll.", MsgBoxStyle.Critical, "No MOS Minimum Number")
                    txtMOS.Focus()
                    Return
                End If
                Dim minMOS1 As Integer = Int32.Parse(txtMOS.Text)
                Dim succMOS1 As Boolean = result1 <= (baseTN1 - minMOS1)
                'report success/partial success/fail with crits and MOS/MOF
                ReportMargin(result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1, minMOS1, succMOS1)
            ElseIf rdoTask.Checked Then
                'report success/fail with crits and MOS/MOF with time taken determined by MOS/MOF
                If txtTimeframe.Text = "" Then
                    MsgBox("You need to enter a numerical timeframe in the Task Base Timeframe textbox.", MsgBoxStyle.Critical, "No Time Frame")
                    txtTimeframe.Focus()
                    Return
                End If
                Dim timeframe As Double = Double.Parse(txtTimeframe.Text)
                Dim timeunits As String = " " + cmbxTimeframe.Text
                If timeunits = "" Then timeunits = " Period(s)"

                'Determine steps of task speedup or partial work to failure
                Dim steps As Integer
                If baseSucc1 Then
                    steps = Math.Floor(MOS1 / 10)
                    timeframe = timeframe * (1 - steps * 0.1)
                Else
                    steps = Math.Floor(MOF1 / 10)
                    timeframe = timeframe * (steps * 0.1)
                End If

                ReportTask(result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1, timeframe, timeunits)
            ElseIf rdoOpposed.Checked Then
                Dim baseTN2, result2, MOS2, MOF2 As Integer
                Dim baseSucc2, critical2, excellent2, severe2
                DoBaseRoll(txtTarget2, ResLeft2, ResRight2, _lastResultLeft2, _lastresultRight2, baseTN2, result2, baseSucc2, critical2, MOS2, excellent2, MOF2, severe2)

                'Fun crazy rules for opposing rolls
                Dim char1Wins, char2Wins As Boolean
                If baseSucc1 And Not baseSucc2 Then
                    char1Wins = True
                    char2Wins = False
                ElseIf Not baseSucc1 And baseSucc2 Then
                    char1Wins = False
                    char2Wins = True
                ElseIf baseSucc1 And baseSucc2 Then
                    If critical1 And critical2 Then
                        If result1 > result2 Then
                            char1Wins = True
                            char2Wins = False
                        ElseIf result1 < result2 Then
                            char1Wins = False
                            char2Wins = True
                        Else
                            char1Wins = False
                            char2Wins = False
                        End If
                    ElseIf critical1 Then
                        char1Wins = True
                        char2Wins = False
                    ElseIf critical2 Then
                        char1Wins = False
                        char2Wins = True
                    ElseIf result1 > result2 Then
                        char1Wins = True
                        char2Wins = False
                    ElseIf result1 < result2 Then
                        char1Wins = False
                        char2Wins = True
                    Else
                        char1Wins = False
                        char2Wins = False
                    End If
                End If

                'report success/failures of both and overall winner.
                ReportOpposed(result1, baseSucc1, critical1, MOS1, excellent1, MOF1, severe1, char1Wins, result2, baseSucc2, critical2, MOS2, excellent2, MOF2, severe2, char2Wins)
            End If
        Else
            'Damage does it's own kind of rolls
            If txtDamageDice.Text = "" Or txtDamageBonus.Text = "" Or txtAP.Text = "" Or txtArmor.Text = "" Then
                MsgBox("You need to enter a value for each of the damage parameters to roll damage.", MsgBoxStyle.Critical, "Missing Damage Parameters")
                Return
            End If
            Dim diceNum As Integer = Int32.Parse(txtDamageDice.Text)
            Dim AP As Integer = Int32.Parse(txtAP.Text)
            Dim Armor As Integer = Int32.Parse(txtArmor.Text)
            Dim EndArmor As Integer = Armor + AP
            If EndArmor < 0 Then EndArmor = 0
            Dim diceBonus As Integer = Int32.Parse(txtDamageBonus.Text)
            Dim damage As Integer = diceBonus
            For i = 1 To diceNum
                damage = damage + _rand.Next(1, 10)
            Next
            Dim enddamage = damage - EndArmor
            If enddamage < 0 Then enddamage = 0

            ReportDamage(diceNum, diceBonus, AP, Armor, damage, enddamage)
        End If

    End Sub

    ''' <summary>
    ''' The core roll function
    ''' </summary>
    ''' <param name="InputTarget">Textbox to take TN from</param>
    ''' <param name="InputResLeft">Force result left for moxie invert. -1 for create new rand</param>
    ''' <param name="InputResRight">Force result right for moxie invert. -1 for create new rand</param>
    ''' <param name="resultLeft">Output pointer to appropriate last to store the result</param>
    ''' <param name="resultRight">Output pointer to appropriate last to store the result</param>
    ''' <param name="baseTN">Output TN</param>
    ''' <param name="result">Output Result</param>
    ''' <param name="baseSucc">Output Success</param>
    ''' <param name="critical">Output critical flag</param>
    ''' <param name="MOS">Output MOS</param>
    ''' <param name="excellent">Output excellent MOS flag</param>
    ''' <param name="MOF">Output MOF</param>
    ''' <param name="severe">Output severe MOF</param>
    ''' <remarks></remarks>
    Private Sub DoBaseRoll(ByVal InputTarget As Windows.Forms.TextBox, ByVal InputResLeft As Integer, ByVal InputResRight As Integer, ByRef resultLeft As Integer, ByRef resultRight As Integer, ByRef baseTN As Integer, ByRef result As Integer, ByRef baseSucc As Boolean, ByRef critical As Boolean, ByRef MOS As Integer, ByRef excellent As Boolean, ByRef MOF As Integer, ByRef severe As Boolean)

        If txtTarget1.Text = "" Then
            MsgBox("You need to enter a target number value in the Target # box in order to roll.", MsgBoxStyle.Critical, "No Target Number")
            InputTarget.Focus()
            Return
        End If

        baseTN = Int32.Parse(InputTarget.Text)

        'Used for moxie inversions or generating rands
        If InputResLeft <> -1 Then
            resultLeft = InputResLeft
        Else
            resultLeft = _rand.Next(0, 9)
        End If
        If InputResRight <> -1 Then
            resultRight = InputResRight
        Else
            resultRight = _rand.Next(0, 9)
        End If
        'Total result
        result = resultLeft * 10 + resultRight
        'Critical?
        critical = (resultLeft = resultRight)
        'Success at no added rules?
        baseSucc = (result <= baseTN)
        'Special outliers
        If result = 0 Then baseSucc = True
        If result = 99 Then baseSucc = False
        'Calc the margin of success or failure
        If baseSucc Then
            MOS = baseTN - result
            MOF = 0
            excellent = (MOS >= 30)
            severe = False
        Else
            MOS = 0
            MOF = result - baseTN
            excellent = False
            severe = (MOF >= 30)
        End If
    End Sub

    ''' <summary>
    ''' Displays the roll for normal rolls
    ''' </summary>
    ''' <param name="result1"></param>
    ''' <param name="baseSucc1"></param>
    ''' <param name="critical1"></param>
    ''' <param name="MOS1"></param>
    ''' <param name="excellent1"></param>
    ''' <param name="MOF1"></param>
    ''' <param name="severe1"></param>
    ''' <remarks></remarks>
    Private Sub ReportNormal(ByVal result1 As Integer, ByVal baseSucc1 As Boolean, ByVal critical1 As Boolean, ByVal MOS1 As Integer, ByVal excellent1 As Boolean, ByVal MOF1 As Integer, ByVal severe1 As Boolean)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------" + vbNewLine + "Char1 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result1.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical1 And excellent1 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            If baseSucc1 Then
                .SelectionColor = Color.Green
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent1 Then
                    .AppendText(" Excellent")
                End If
                .AppendText(" Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS1.ToString)
            Else
                .SelectionColor = Color.Red
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If severe1 Then
                    .AppendText(" Severe")
                End If
                .AppendText(" Failure")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF1.ToString)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()
        End With

    End Sub

    ''' <summary>
    ''' Displays the roll for simple success as strong/weak success
    ''' </summary>
    ''' <param name="result1"></param>
    ''' <param name="baseSucc1"></param>
    ''' <param name="critical1"></param>
    ''' <param name="MOS1"></param>
    ''' <param name="excellent1"></param>
    ''' <param name="MOF1"></param>
    ''' <param name="severe1"></param>
    ''' <remarks></remarks>
    Private Sub ReportSimple(ByVal result1 As Integer, ByVal baseSucc1 As Boolean, ByVal critical1 As Boolean, ByVal MOS1 As Integer, ByVal excellent1 As Boolean, ByVal MOF1 As Integer, ByVal severe1 As Boolean)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------" + vbNewLine + "Char1 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result1.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical1 And excellent1 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            If baseSucc1 Then
                .SelectionColor = Color.Green
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent1 Then
                    .AppendText(" Excellent")
                End If
                .AppendText(" Strong Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS1.ToString)
            Else
                .SelectionColor = Color.DarkGoldenrod
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                .AppendText(" Weak Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF1.ToString)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()
        End With
    End Sub

    ''' <summary>
    ''' Displays the roll for margin as success/partial success based on minimum MOS
    ''' </summary>
    ''' <param name="result1"></param>
    ''' <param name="baseSucc1"></param>
    ''' <param name="critical1"></param>
    ''' <param name="MOS1"></param>
    ''' <param name="excellent1"></param>
    ''' <param name="MOF1"></param>
    ''' <param name="severe1"></param>
    ''' <param name="minMOS1"></param>
    ''' <param name="succMOS"></param>
    ''' <remarks></remarks>
    Private Sub ReportMargin(ByVal result1 As Integer, ByVal baseSucc1 As Boolean, ByVal critical1 As Boolean, ByVal MOS1 As Integer, ByVal excellent1 As Boolean, ByVal MOF1 As Integer, ByVal severe1 As Boolean, ByVal minMOS1 As Integer, ByVal succMOS As Boolean)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------" + vbNewLine + "Char1 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result1.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical1 And excellent1 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)

            If baseSucc1 Then
                .SelectionColor = Color.Green
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent1 Then
                    .AppendText(" Excellent")
                End If
                If succMOS Then
                    .AppendText(" Full")
                Else
                    .AppendText(" Partial")
                End If

                .AppendText(" Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS1.ToString)
                .SelectionFont = .Font
                .AppendText(" with a minimum MOS of ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(minMOS1.ToString)
            Else
                .SelectionColor = Color.Red
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If severe1 Then
                    .AppendText(" Severe")
                End If
                .AppendText(" Failure")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF1.ToString)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()

        End With

    End Sub

    ''' <summary>
    ''' Displays the roll for task and time it takes
    ''' </summary>
    ''' <param name="result1"></param>
    ''' <param name="baseSucc1"></param>
    ''' <param name="critical1"></param>
    ''' <param name="MOS1"></param>
    ''' <param name="excellent1"></param>
    ''' <param name="MOF1"></param>
    ''' <param name="severe1"></param>
    ''' <param name="timeframe"></param>
    ''' <param name="timeunits"></param>
    ''' <remarks></remarks>
    Private Sub ReportTask(ByVal result1 As Integer, ByVal baseSucc1 As Boolean, ByVal critical1 As Boolean, ByVal MOS1 As Integer, ByVal excellent1 As Boolean, ByVal MOF1 As Integer, ByVal severe1 As Boolean, ByVal timeframe As Double, ByVal timeunits As String)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------" + vbNewLine + "Char1 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result1.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical1 And excellent1 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            If baseSucc1 Then
                .SelectionColor = Color.Green
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent1 Then
                    .AppendText(" Excellent")
                End If
                .AppendText(" Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS1.ToString)
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". Task will take ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(timeframe.ToString + timeunits)
            Else
                .SelectionColor = Color.Red
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If severe1 Then
                    .AppendText(" Severe")
                End If
                .AppendText(" Failure")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF1.ToString)
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". Task will be recognized as failure after ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(timeframe.ToString + timeunits)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()
        End With
    End Sub

    ''' <summary>
    ''' Displays the rolls for opposed tests
    ''' </summary>
    ''' <param name="result1"></param>
    ''' <param name="baseSucc1"></param>
    ''' <param name="critical1"></param>
    ''' <param name="MOS1"></param>
    ''' <param name="excellent1"></param>
    ''' <param name="MOF1"></param>
    ''' <param name="severe1"></param>
    ''' <param name="char1Wins"></param>
    ''' <param name="result2"></param>
    ''' <param name="baseSucc2"></param>
    ''' <param name="critical2"></param>
    ''' <param name="MOS2"></param>
    ''' <param name="excellent2"></param>
    ''' <param name="MOF2"></param>
    ''' <param name="severe2"></param>
    ''' <param name="char2Wins"></param>
    ''' <remarks></remarks>
    Private Sub ReportOpposed(ByVal result1 As Integer, ByVal baseSucc1 As Boolean, ByVal critical1 As Boolean, ByVal MOS1 As Integer, ByVal excellent1 As Boolean, ByVal MOF1 As Integer, ByVal severe1 As Boolean, ByVal char1Wins As Boolean, ByVal result2 As Integer, ByVal baseSucc2 As Boolean, ByVal critical2 As Boolean, ByVal MOS2 As Integer, ByVal excellent2 As Boolean, ByVal MOF2 As Integer, ByVal severe2 As Boolean, ByVal char2Wins As Boolean)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------")
            .AppendText(vbNewLine + "Char1 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result1.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical1 And excellent1 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            If baseSucc1 Then
                .SelectionColor = Color.Green
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent1 Then
                    .AppendText(" Excellent")
                End If
                .AppendText(" Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS1.ToString)
            Else
                .SelectionColor = Color.Red
                If critical1 Then
                    .AppendText(" CRITICAL")
                End If
                If severe1 Then
                    .AppendText(" Severe")
                End If
                .AppendText(" Failure")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF1.ToString)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()

            .AppendText(vbNewLine + "Char2 rolled a ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            .AppendText(result2.ToString)
            .SelectionFont = .Font
            .AppendText(". A")
            If Not critical2 And excellent2 Then .AppendText("n")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            If baseSucc2 Then
                .SelectionColor = Color.Green
                If critical2 Then
                    .AppendText(" CRITICAL")
                End If
                If excellent2 Then
                    .AppendText(" Excellent")
                End If
                .AppendText(" Success")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText("!!! MOS was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOS2.ToString)
            Else
                .SelectionColor = Color.Red
                If critical2 Then
                    .AppendText(" CRITICAL")
                End If
                If severe2 Then
                    .AppendText(" Severe")
                End If
                .AppendText(" Failure")
                .SelectionFont = .Font
                .SelectionColor = .ForeColor
                .AppendText(". MOF was ")
                .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
                .AppendText(MOF2.ToString)
            End If
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(".")
            .ScrollToCaret()

            .AppendText(vbNewLine + "Results in: ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 2, FontStyle.Bold)
            If char1Wins Then
                .AppendText("Char1 wins!!!")
            ElseIf char2Wins Then
                .AppendText("Char2 wins!!!")
            Else
                .AppendText("No one wins!!!")
            End If
            .SelectionFont = .Font
            .AppendText(".")
            .ScrollToCaret()
        End With
    End Sub

    ''' <summary>
    ''' Displays the roll for damage
    ''' </summary>
    ''' <param name="diceNum"></param>
    ''' <param name="diceBonus"></param>
    ''' <param name="AP"></param>
    ''' <param name="Armor"></param>
    ''' <param name="damage"></param>
    ''' <param name="enddamage"></param>
    ''' <remarks></remarks>
    Private Sub ReportDamage(ByVal diceNum As Integer, ByVal diceBonus As Integer, ByVal AP As Integer, ByVal Armor As Integer, ByVal damage As Integer, ByVal enddamage As Integer)
        With rtxtHistory
            .SelectionColor = .ForeColor
            .SelectionFont = .Font
            .AppendText(vbNewLine + vbNewLine + "--------------------------------------------------------------" + vbNewLine + "Rolling ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            .AppendText(diceNum.ToString)
            .SelectionFont = .Font
            .AppendText("d10")
            If diceBonus >= 0 Then .AppendText("+")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            .AppendText(diceBonus.ToString)
            .SelectionFont = .Font
            .AppendText(" (AP ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            .AppendText(AP.ToString)
            .SelectionFont = .Font
            .AppendText("). Rolled ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            .AppendText(damage.ToString)
            .SelectionFont = .Font
            .AppendText(" base versus armor ")
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 1, FontStyle.Bold)
            .AppendText(Armor.ToString)
            .SelectionFont = .Font
            .AppendText(" for total of ")
            .SelectionColor = Color.Green
            .SelectionFont = New Font(.Font.FontFamily, .Font.Size + 3, FontStyle.Bold)
            .AppendText(enddamage.ToString)
            .SelectionFont = .Font
            .SelectionColor = .ForeColor
            .AppendText(" damage.")
            .ScrollToCaret()
        End With
    End Sub

#End Region

End Class
